package edu.ubb.scrumster.controller.backendController;

import edu.ubb.scrumster.model.model.Sprint;
import edu.ubb.scrumster.model.model.User;
import edu.ubb.scrumster.model.model.UserStory;
import edu.ubb.scrumster.model.repository.CommentRepository;
import edu.ubb.scrumster.model.repository.SprintRepository;
import edu.ubb.scrumster.model.repository.TaskRepository;
import edu.ubb.scrumster.model.repository.UserRepository;
import edu.ubb.scrumster.model.repository.UserStoryRepository;

public class LoginController {

	public User login(String username, String password) {
		User u = null;
		try {
			u = new UserRepository().login(username, password);
			u.getScrum().setSprints(
					new SprintRepository().getSprintByScrum(u.getScrum()
							.getId()));
			for (Sprint s : u.getScrum().getSprints()) {
				s.setUserStories(new UserStoryRepository()
						.getUserStoryBySprint(s.getId()));
				for (UserStory us : s.getUserStories()) {
					us.setTasks(new TaskRepository().getTaskByUserStory(us
							.getId()));
				}
			}
			u.getScrum().setMembers(new UserRepository().getUserByScrum(u.getScrum().getId()));
			u.getScrum().setComments(new CommentRepository().getCommentByScrum(u.getScrum().getId()));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return u;
	}
}
